<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title>Binding Test Single</title>
    <link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.10.0.css">
</head>
<body>
    <div id="qunit"></div>
    <div id="qunit-fixture"></div>
    <script src="https://code.jquery.com/qunit/qunit-2.10.0.js"></script>

    <script type="text/javascript">
    QUnit.module('BindingTestSingle', (hooks) =>
    {
        hooks.before(async () =>
        {
            await CefSharp.BindObjectAsync("boundAsync");
        });

        QUnit.test("Pass callback(promise) that is conditionally invoked:", async (assert) =>
        {
            let callback = function (msg)
            {
                return new Promise((resolve, reject) =>
                {
                    setTimeout(() =>
                    {
                        resolve(msg);
                    }, 300);
                });
            };

            const expectedResult = "Callback has not been invoked";
            const actualResult = await boundAsync.javascriptOptionalCallbackEvalPromise(false, expectedResult, callback);
            assert.equal(expectedResult, actualResult, "Echo response after promise execution");

            const expectedSecondResult = "Callback has been invoked";
            const actualSecondResult = await boundAsync.javascriptOptionalCallbackEvalPromise(true, expectedSecondResult, callback);
            assert.equal(expectedSecondResult, actualSecondResult, "Echo response after promise execution");
        });
    });
    </script>

</body>
</html>
